package com.ratta.supernote.note.plugincore.view.touchview;

import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.ViewManagerDelegate;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.viewmanagers.TouchViewManagerDelegate;
import com.facebook.react.viewmanagers.TouchViewManagerInterface;

import java.util.Map;

public class TouchViewManager extends ViewGroupManager<TouchView> implements TouchViewManagerInterface<TouchView> {
    static final String NAME = "TouchView";

    private final ViewManagerDelegate<TouchView> mDelegate;


    public TouchViewManager(ReactApplicationContext context) {
        mDelegate = new TouchViewManagerDelegate<>(this);
    }

    @NonNull
    @Override
    public String getName() {
        return NAME;
    }

    @NonNull
    @Override
    protected TouchView createViewInstance(@NonNull ThemedReactContext themedReactContext) {
        return new TouchView(themedReactContext);
    }

    @Nullable
    @Override
    protected ViewManagerDelegate<TouchView> getDelegate() {
        return mDelegate;
    }

    @Nullable
    @Override
    public Map getExportedCustomBubblingEventTypeConstants() {
        return MapBuilder.builder().put(
                        "onTouchType",
                        MapBuilder.of("phasedRegistrationNames",
                                MapBuilder.of("bubbled", "onTouchType"))
                )
                .put("onClick",
                        MapBuilder.of("phasedRegistrationNames",
                                MapBuilder.of("bubbled", "onClick")))
                .build();
    }


    @Override
    @ReactProp(name = "forbidTouchType")
    public void setForbidTouchType(TouchView view, int value) {
        view.setForbidTouchType(value);
    }
}
